// Componet/Componet.js
const lbbService = require('../../pages/service/service.js');
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    propArray: {
      type: Array,
    },
    top:{
      type:String, 
      value:'105'
    },
    filter:{
      type:Boolean,
      value:false
    },
    filterArr: {
      type: Array,
    },
    installMaster: {
      type: Array,
    },
    masterShow:{
      type:Boolean,
      value:true
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    hostpitalList:[],
    filterIndex:0,
    cityShow: '0',
    provIndex: 0,
    cityIndex: 0,
    regionIndex: 0,
    hospitalIndex:0,
    masterIndex:0,
    provId: 0,
    cityId: 0,
    regionId: 0,
    hospitalId:0,
    masterId:0,
    masterName:'师傅',
    provName: '省',
    cityName: '市',
    regionName: '区/县',
    hospitalName:"医院",
    master_animationData: {}, 
    prov_animationData: {}, 
    city_animationData: {}, 
    region_animationData: {},
    hostpital_animationData:{}
  },
  /**
   * 组件的方法列表
   */
  methods: {　　　 //option的显示与否
    /**
     * 附加筛选条件变化
     */
    pickerChange:function (e) {
      let filterIndex = e.detail.value;
      this.setData({
        filterIndex: filterIndex,
    
      })
      let idArray = [this.data.provId, this.data.cityId, this.data.regionId];
      this.triggerEvent('filterevent', {idArray:idArray,filterIndex:filterIndex});
    },
    masterToggle:function(){
      this.pickUp()
      if (this.data.cityShow=='5') {
        this.setData({
          cityShow: '0',
        })
      } else {
        this.toggleAnimation(180)
        this.setData({
          cityShow: '5',
        })
      }
      this.setData({
        master_animationData: this.animation.export()
      })
    },
    provToggle: function() {
      this.pickUp()
      if (this.data.cityShow=='1') {
        this.setData({
          cityShow: '0',
        })
      } else {
        this.toggleAnimation(180)
        this.setData({
          cityShow: '1',
        })
      }
      this.setData({
        prov_animationData: this.animation.export()
      })
    },
    cityToggle: function() {
      this.pickUp()
      if (this.data.cityShow=='2') {
        this.setData({
          cityShow: '0',
        })
      } else {
        this.toggleAnimation(180)
        this.setData({
          cityShow: '2',
        })
      }
      this.setData({
        city_animationData: this.animation.export()
      })
    },
    regionToggle: function() {
      this.pickUp()
      if (this.data.cityShow == '3') {
        this.setData({
          cityShow: '0',
        })
      } else {
        this.toggleAnimation(180)
        this.setData({
          cityShow: '3',
        })
      }
      this.setData({
        region_animationData: this.animation.export()
      })
    },
    hospitalToggle: function() {
      this.pickUp()
      if (this.data.cityShow=='4') {
        this.setData({
          cityShow: '0',
        })
      } else {
        this.toggleAnimation(180)
        this.setData({
          cityShow: '4',
        })
      }
      this.setData({
        hostpital_animationData: this.animation.export()
      })
    },
    //创建动画

    toggleAnimation: function(angle) {
      var animation = wx.createAnimation({
        timingFunction: "ease"
      })
      this.animation = animation;
      animation.rotate(angle).step()
    },
    //设置内容
    setProv: function(e) {
      let provIndex = e.target.dataset.index; //当前点击的索引
      let provName = e.target.dataset.provName; 
      let provId = e.target.dataset.id; 
      this.toggleAnimation(0)
      this.setData({
        cityShow: '0',
        provIndex,
        provName,
        cityName: '市', 
        regionName: '区/县', 
        hospitalName:"医院",
        provId,
        cityIndex: 0,
        cityId:0,
        regionIndex: 0,
        regionId:0,
        hospitalIndex:0,
        hospitalId:0,
        prov_animationData: this.animation.export()
      })
      let idArray = [this.data.provId, this.data.cityId, this.data.regionId,0,this.data.masterId]
      this.getHospitalList(idArray)
      this.triggerEvent('myevent', idArray)
    },
    setCity: function (e) {
      let cityIndex = e.target.dataset.index; //当前点击的索引
      let cityName = e.target.dataset.cityName;
      let provIndex = this.data.provIndex
      let cityId = e.target.dataset.cityId;
      this.toggleAnimation(0)
      this.setData({
        cityShow: '0',
        cityIndex,
        cityId,
        cityName,
        regionName: '区/县', 
        hospitalName:"医院",
        regionIndex: 0,
        regionId:0,
        hospitalIndex:0,
        hospitalId:0,
        city_animationData: this.animation.export()
      })
      let idArray = [this.data.provId, this.data.cityId, this.data.regionId,0,this.data.masterId]
      this.getHospitalList(idArray)
      this.triggerEvent('myevent', idArray)
    },
    setRegion: function (e) {
      let regionIndex = e.target.dataset.index; //当前点击的索引
      let regionName = e.target.dataset.regionName;
      let regionId = e.target.dataset.regionId;
      this.toggleAnimation(0)
      this.setData({
        cityShow: '0',
        regionIndex,
        regionId,
        regionName,
        region_animationData: this.animation.export()
      })
      let idArray = [this.data.provId, this.data.cityId, this.data.regionId,0,this.data.masterId]
      this.getHospitalList(idArray)
      this.triggerEvent('myevent', idArray)
    },
    setHospital: function (e) {
      let hospitalIndex = e.target.dataset.index; //当前点击的索引
      let hospitalName = e.target.dataset.hospitalName;
      let hospitalId = e.target.dataset.hospitalId;
      this.toggleAnimation(0)
      this.setData({
        cityShow: '0',
        hospitalIndex,
        hospitalId,
        hospitalName,
        hostpital_animationData: this.animation.export()
      })
      let idArray = [this.data.provId, this.data.cityId, this.data.regionId,this.data.hospitalId,this.data.masterId]
      this.triggerEvent('myevent', idArray)
    },
    setMaster:function(e){
      let masterIndex = e.target.dataset.index; //当前点击的索引
      let masterId = e.target.dataset.masterId;
      let masterName = e.target.dataset.masterName;
      this.toggleAnimation(0)
      this.setData({
        cityShow: '0',
        masterIndex,
        masterId,
        masterName,
        master_animationData: this.animation.export()
      })
      let idArray = [this.data.provId, this.data.cityId, this.data.regionId,0,masterId]
      this.getHospitalList(idArray)
      this.triggerEvent('myevent', idArray)
    },
    getHospitalList: function (array) {
      let that = this
        lbbService.getSearchHospitalList({
          provinceId:array[0],
          cityId:array[1],
          villageId:array[2],
          uid:array[4],
        }, function (res) {
            that.setData({
              hostpitalList: res.data
            })
        })
    
    },
    pickUp: function(){
      if (this.data.cityShow == '1') {
        this.toggleAnimation(0)
        this.setData({
          prov_animationData: this.animation.export()
        })
      } else if (this.data.cityShow == '2') {
        this.toggleAnimation(0)
        this.setData({
          city_animationData: this.animation.export()
        })
      } else if (this.data.cityShow == '3') {
        this.toggleAnimation(0)
        this.setData({
          region_animationData: this.animation.export()
        })
      }
      else if (this.data.cityShow == '4') {
        this.toggleAnimation(0)
        this.setData({
          hostpital_animationData: this.animation.export()
        })
      }
      else if (this.data.cityShow == '5') {
        this.toggleAnimation(0)
        this.setData({
          master_animationData: this.animation.export()
        })
      }
    }
  }
})